package com.campus_information_portal.controller;

import com.campus_information_portal.entity.MarkCondition;
import com.campus_information_portal.entity.Warning;
import com.campus_information_portal.service.StudentService;
import com.campus_information_portal.service.TermService;
import com.campus_information_portal.service.WarningService;
import com.campus_information_portal.util.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author 20155884 王晓阳
 * @className : WarningController
 * @Description
 * @create 2018/05/30 14:00$
 **/
@Controller
@RequestMapping("/warning")
@ResponseBody
@CrossOrigin(origins = "*")
public class WarningController {
    @Autowired
    private WarningService warningService;
    @Autowired
    private TermService termService;
    @Autowired
    private StudentService studentService;

    //学业警告，1.查询每个学生某个学期所修学分 2.查询某学期本应修的全部学分
    @RequestMapping(value = "/selectWarning", method = RequestMethod.GET)
    public Message selectWarning(MarkCondition markCondition) {
        int termid = termService.queryTermId(markCondition.getTermYear(), markCondition.getTermNum()).getData().getTermId();
        markCondition.setTermId(termid);
        return warningService.findStuCredithour1(markCondition);
    }

    //添加学业警示
    @RequestMapping(value = "/addWarning", method = RequestMethod.GET)
    public Message selectMark(MarkCondition markCondition) {
        System.out.println("-addWarning-" + markCondition.toString());
        //通过学年学期查询学期id
        int termid = termService.queryTermId(markCondition.getTermYear(), markCondition.getTermNum()).getData().getTermId();
        markCondition.setTermId(termid);
        //通过学号找学生id
        int stuInfoId = studentService.queryStuIdByStuNum(markCondition.getStuNum()).getData().getStuInfoId();
        Warning warning = new Warning();
        warning.setTermId(termid);
        warning.setStuInfoId(stuInfoId);
        warning.setWarningNum(markCondition.getWarningNum());
        return warningService.addWarning(warning);
    }

    //学生动态查询学业警示
    @RequestMapping(value = "/studentWarning", method = RequestMethod.GET)
    public Message studentWarning(MarkCondition markCondition) {
        System.out.println("warning:" + markCondition.toString());
        return warningService.selectWarning(markCondition);
    }
}
